package com.pwrd.sframe.support.util;

/**
 * 秒表
 * @Auther syc.
 * @Date 2017/2/8 11:20.
 */
public class Stopwatch {

    private long startTime;

    private long endTime;

    private long lastingTime;

    public static Stopwatch createStarted() {
        Stopwatch s = new Stopwatch();
        s.start();
        return s;
    }

    public static Stopwatch createUnstarted() {
        return new Stopwatch();
    }

    public void start() {
        startTime = System.currentTimeMillis();
    }

    public void stop() {
        endTime = System.currentTimeMillis();
        lastingTime += endTime - startTime;
    }

    /**
     * 持续时间
     * @return
     */
    public long lastTime() {
        return lastingTime;
    }

    /**
     * 重置秒表
     */
    public void reset() {
        lastingTime = 0;
    }

    /**
     * 重置后开始
     */
    public void resetAndStart() {
        reset();
        start();
    }
}
